#ifndef PLAYERS_H
#define PLAYERS_H



#include "init.h"
#include "game.h"
#include "ai.h"
#include <string>
#include <vector>



using std::string;
using std::vector;



//! @brief Player types
enum PlayerType { local, ai, network };



class unit;
class algorithm;



//! Class representing a single player
class player
{

public:

	/** @brief Constructor creates new player and sets starting time
	*	@param i player's id
	*	@param n player's name
	*	@param t player's type
	*/
	player( int i, string n, PlayerType t );

	//! Destructor deletes the player and all his units
	~player();

	/**	@brief	Creates deep clone od player including clone of his units
	*	@return	pointer to the clone
	*/
	player* clone();

	/** @brief	Gets remaining time
	*	@return	remaining time
	*/
	int get_time() { return time; };
	/** @brief	Gets palyers id
	*	@return	player's id
	*/
	int get_id() { return id; };
	/** @brief Sets players game time
	*	@param t time to be set
	*/
	void set_time( int t ) { time = t; };
	/** @brief	Gets player's type
	*	@return	player's type
	*/
	PlayerType get_type() { return typ; };
	/** @brief Sets player's name
	*	@param n name to be set
	*/
	void set_name( string n ) { name = n; };
	/** @brief	Gets player's name
	*	@return	player's name
	*/
	string get_name() { return name; };
	/** @brief	Obtains information if the player is in game or not
	*	@return	true, if player is in game, else not
	*/
	bool is_in_game() { return in_game; };
	//! @brief Set's player out of the game (when he has not any units left)
	void set_out() { in_game = false; };
	/** @brief	Buys unit from prototypes map
	*	@param	u unit to buy, constraint: u != 0
	*	@param	x x coordinate, where to place new unit, constraint: x < map->size_x
	*	@param	y y coordinate, where to place new unit, constraint: y < map->size_y
	*	@return	true, if the action was successful, else false
	*/
	bool buy_unit( unit* u, unsigned int x, unsigned int y );
	/** @brief	Sells own unit
	*	@param	n unit's 
	*	@return	true, if the action was successful, else false
	*/
	bool sell_unit( unsigned int n );


	//! vector of player's units
	vector< unit* > units;
	//! pointer to used AI algorithm (when not ai player, pointer == 0)
	algorithm* ai_algorithm;


private:

	//! Player type
	PlayerType typ;
	//! Player's unique id
	int id;
	//! Player's name
	string name;
	//! Player's remeining time in turn, or remaining money while buying units
	int time;
	//! Whether player is still playing, or out
	bool in_game;

};



#endif